<?php

namespace App\Admin\Controllers;

use App\Models\Config;
use App\Models\Category;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;


class ConfigController extends Controller
{
    use ModelForm;
    public $header = '设置';
    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header($this->header);
            $content->description('列表');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     *
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {
            $content->header('编辑'.$this->header);
            $content->description('设置');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * 创建组织
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {
            $content->header('创建'.$this->header);

            $content->body($this->form());

        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
//    protected function grid()
//    {
//        return Admin::grid(Config::class, function (Grid $grid) {
//            $grid->id('ID')->sortable();
//            $grid->title('标题')->editable();
//            $grid->type('位置')->editable('select', [1 => '左上角', 2 => '左侧栏目标题', 3 => '右侧栏目标题']);
//
//            $grid->actions(function (Grid\Displayers\Actions $actions) {
//                $actions->disableView();
////                $actions->disableDelete();
////                $actions->disableEdit();
//            });
//        });
//    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Config::class, function (Form $form) {
            $form->tab('配置', function ($form) {
                $form->text('left_top_title','左上角标题')->rules('required');
                $form->text('left_title','左侧栏目名称')->rules('required');
                $form->text('right_title','右侧栏目名称')->rules('required');
                $form->disableEditingCheck();
                $form->disableCreatingCheck();
                $form->disableViewCheck();
                $form->tools(function (Form\Tools $tools) {
                    $tools->disableDelete();
                    $tools->disableView();
                    $tools->disableList();
                });
                $form->saved(function (Form $form) {

                    // 跳转页面
                    return redirect('/admin/config/1/edit');

                });
            });



        });
    }
}
